<%@ page language="java"  pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="/struts-dojo-tags" prefix="sx"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="<s:url value="/style.css"/>" rel="stylesheet" type="text/css"/>
<title>Patient List</title>
<style>
	viewerPatientList {
		margin-top:50px;
	}
	
	#patientTable td {
		text-align:center;
	}
</style>
<sx:head/>
</head>
<body>
<jsp:include page="/navigation/navigation.jsp"/>
	<div id="mainBox">
		<center>
			<h2>Patients</h2>
			<s:if test='#session.currentUser.getType()=="1"'>
				<center>
						<s:form name="searchPatientForm" action="searchPatient" method="post">
							<table>
							<tr>
								<td><input type="submit" value="Search"/></td>
								<td><input type="text" name="searchContent"/></td>
								<td>
									<select name="searchType" >
											<s:iterator value="searchTypeMap">
									    		<option value="<s:property value="key"/>"><s:property value="value"/></option>
											</s:iterator>
									</select>
								</td>
							</tr>
							<s:hidden name = "selectedEmployeeId"  value = "%{selectedEmployeeId}"/>
							</table>
						</s:form>
				</center>
				<center>
				  <s:form name="searchPatientByLastVisitDate" action="searchPatientByLastVisitDate" method="post">
				  	<table>
				  	<tr>
				  		<td>Search Patient By Last Visit Date</td>
						<td><sx:datetimepicker name="lastVisitDate" label="Last Visit Date"
								displayFormat="yyyy-MM-dd" /></td>
						<s:hidden name = "selectedEmployeeId"  value = "%{selectedEmployeeId}"/>
						<td><input type="submit" value="SearchByLastVisitDate" /></td>
				  	</tr>
				  	</table>
				  </s:form>
				</center>
				
			</s:if>
			</center>
			
			<center>
			<div id="ownerPatientList">
				<s:if test='actionMode=="showDoctorPatient"'>
					<h3>Owner</h3>
					<table width="800px" id = "patientTable">
					<col width="150" />
					<col width="150" />
					<col width="200" />
					<col width="130" />
					<col width="100" />
					<col width="150" />
						<thead>
							<tr>
								<th>Name</th>
								<th>Phone</th>
								<th>OHIP</th>
								<th>LastVisitTime</th>
								<th>currentHealth</th>
								<th>Visitations</th>
								<th>Edit</th>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="ownerPatients">
							<tr>
								<td><s:property value="name"/></td>
								<td><s:property value="phone" /></td>
								<td><s:property value="ohip"/></td>
								<s:if test='<s:property value="lastVisitTime" />==null' >
									<td>Never visited</td>
								</s:if>
								<s:else>
									<td><s:property value="lastVisitTime" /></td>
								</s:else>
								<td><s:property value="currentHealth" /></td>
								<td><a href="<s:url action='initPatientVisitationListPageByPatientId'><s:param name="selectedPatientId" value="%{id}" /></s:url>">visitations</a></td>
								<td><a href="<s:url action='initPatientUpdatePage'><s:param name="selectedPatientId" value="%{id}" /></s:url>">edit</a></td>
							</tr>
							</s:iterator>
						</tbody>
					</table>
				</s:if>
				</div>
				</center>
				
				<div>
				<s:if test='actionMode=="showStaffPatient"'>
					<center>
				<table width="900px" id = "patientTable">
					<col width="200" />
					<col width="150" />
					<col width="200" />
					<col width="130" />
					<col width="100" />
					<col width="150" />
					<col width="150" />
						<thead>
							<tr>
								<th>Name</th>
								<th>Phone</th>
								<th>LastVisitTime</th>
								<th>currentHealth</th>
								<th>Visitations</th>
								<th>Edit</th>
								<th>Create appointment</th>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="ownerPatients">
							<tr>
								<td><s:property value="name"/></td>
								<td><s:property value="phone" /></td>
								<s:if test='<s:property value="lastVisitTime" />==null' >
									<td>Never visited</td>
								</s:if>
								<s:else>
									<td><s:property value="lastVisitTime" /></td>
								</s:else>
								<td><s:property value="currentHealth" /></td>
								<td><a href="<s:url action='initPatientVisitationListPageByPatientId'><s:param name="selectedPatientId" value="%{id}" /></s:url>">visitations</a></td>
								<td><a href="<s:url action='initPatientUpdatePage'><s:param name="selectedEmployeeId" value="%{#session.currentUser.id}" /><s:param name="selectedPatientId" value="%{id}" /></s:url>">edit</a></td>
								<td><a href="<s:url action='initAppointmentCreatePage'><s:param name="selectedPatientId" value="%{id}" /></s:url>">new appointment</a></td>
							</tr>
							</s:iterator>
						</tbody>
					</table>
					</center>
				</s:if>
				</div>
				
				<center>
				<s:if test='actionMode=="showDoctorPatient"'>
				<div id="viewerPatientList">
				<h3>Viewer</h3>
				
				<table width="800px" id = "patientTable">
					<col width="150" />
					<col width="150" />
					<col width="200" />
					<col width="130" />
					<col width="130" />
					<col width="100" />
						<thead>
							<tr>
								<th>Name</th>
								<th>defaultDoctorName</th>
								<th>Phone</th>
								<th>LastVisitTime</th>
								<th>currentHealth</th>
								<th>Visitations</th>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="viewerPatients">
							<tr>
								<td><s:property value="key.name" /></td>
								<td><s:property value="value.name" /></td>
								<td><s:property value="key.phone" /></td>
								<s:if test='<s:property value="key.lastVisitTime" />==null' >
									<td>Never visited</td>
								</s:if>
								<s:else>
									<td><s:property value="key.lastVisitTime" /></td>
								</s:else>
								<td><s:property value="key.currentHealth" /></td>
						
								<td><a href="<s:url action='initPatientVisitationListPageByPatientId'><s:param name="selectedPatientId" value="%{key.id}" /></s:url>">visitations</a></td>
							</tr>
							</s:iterator>
						</tbody>
					</table>
				</div>
				</s:if>
				
			</center>
		</div>
</body>
</html>